﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LastTermNumberItem : MonoBehaviour
{
    public Text m_NumberL;
    public Text m_PrizeL;
    public Button m_RecivePrizeB;
    int m_HitNumber=0;
    int m_SelfNumber=0;
    public CallbackIntInt CallbackOnRecivePrize;
    
    
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public void Init(int selfNumber, int prizeNumber)
    {
        m_SelfNumber = selfNumber;
        m_NumberL.text = selfNumber.ToString().PadLeft(4, '0');
        CheckPrize(selfNumber, prizeNumber);
    }

    public void CheckPrize(int selfNumber, int prizeNumber)
    {
        m_HitNumber = 0;
        var selfNumberS = selfNumber.ToString().PadLeft(4, '0');
        var prizeNumberS = prizeNumber.ToString().PadLeft(4, '0');
        for (int i=0; i< selfNumberS.Length && i < prizeNumberS.Length; ++i)
        {
            if(selfNumberS[i] == prizeNumberS[i])
            {
                m_HitNumber++;
            }
        }
        if(m_HitNumber > 0)
            m_RecivePrizeB.gameObject.SetActive(true);
        switch (m_HitNumber)
            {
                case 4:
                    m_PrizeL.text = "一等奖";
                    m_PrizeL.color = new Vector4(1, 0, 1, 1);
                    break;
                case 3:
                    m_PrizeL.text = "二等奖";
                    m_PrizeL.color = new Vector4(0, 0, 1, 1);
                    break;
                case 2:
                    m_PrizeL.text = "三等奖";
                    m_PrizeL.color = new Vector4(0.2f, 0.6f, 0.2f, 1);
                    break;
                case 1:
                    m_PrizeL.text = "四等奖";
                    m_PrizeL.color = new Vector4(0, 0, 0, 1);
                    break;
            default:
                m_PrizeL.text = "谢谢惠顾";
                break;
            }
    }
    public void OnRecivePrize()
    {
        if(CallbackOnRecivePrize != null)
            CallbackOnRecivePrize(m_HitNumber, m_SelfNumber);
        m_RecivePrizeB.gameObject.SetActive(false);
    }

}
